package com.heima.update;

import com.heima.domain.GetIndex;
import com.heima.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class UpdateStudent {
    public void updateStudent(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入要修改的学生学号:");
            String did = sc.next();
            GetIndex getIndex = new GetIndex();
            int index = getIndex.getIndex(list, did);
            if (index == -1) {
                System.out.println("查无此人请重新输入!");
            } else {
                System.out.println("请输入新的学生姓名:");
                String newName = sc.next();
                System.out.println("请输入新的学生年龄:");
                int newAge = sc.nextInt();
                System.out.println("请输入新的学生生日:");
                String newBirthday = sc.next();
                Student stu = new Student(did, newName, newAge, newBirthday);
                list.set(index, stu);
                System.out.println("修改成功!");
                break;
            }
        }
    }
}
